import { UpdateRoomDto } from './dto/update-room.dto';
import {
  Body,
  Controller,
  Delete,
  Get,
  Param,
  ParseIntPipe,
  Patch,
  Post,
  Query,
  UploadedFile,
  UploadedFiles,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
import { Condition } from 'custom';
import { CreateRoomDto } from './dto/create-room.dto';
import { RoomService } from './room.service';

@Controller('room')
export class RoomController {
  constructor(private readonly roomService: RoomService) {}

  //添加房间
  @Post()
  @UseInterceptors(FilesInterceptor('photo'))
  create(@Body() createRoomDto: CreateRoomDto, @UploadedFiles() files) {
    return this.roomService.create(createRoomDto, files);
  }
  //查询推荐房间
  @Get('some')
  getSome(@Query('key', ParseIntPipe) key: number) {
    return this.roomService.getSome(key);
  }

  //关键词搜索房间
  @Get('keyword')
  findByKeyword(@Query('keyword') keyword: string) {
    return this.roomService.findByKeyword(keyword);
  }
  //条件查询
  @Get('condition')
  findByCondition(
    @Query()
    condition: Condition,
  ) {
    return this.roomService.findByCondition(condition);
  }
  @Get()
  findAll(){
    return this.roomService.findAll()
  }
  //分页获取房间
  @Get('page')
  findByPage(
    @Query('page', ParseIntPipe) page: number,
    @Query('take', ParseIntPipe) take: number,
  ) {
    let skip = (page - 1) * take;
    return this.roomService.findByPage(skip, take);
  }
  @Get('count')
  findCount() {
    return this.roomService.findCount();
  }
  //更具ID获取房间
  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.roomService.findOne(+id);
  }
  //更新房间图片
  @Patch('photo/:id')
  updatePhoto(@Param('id', ParseIntPipe) id: number, @Body() fileInfo: any) {
    return this.roomService.updatePhoto(id, fileInfo);
  }
  //更新房间数据
  @Patch(':id')
  update(@Param('id', ParseIntPipe) id: number, @Body() updateRoomDto: any) {
    return this.roomService.update(id, updateRoomDto);
  }

  //添加房间图片
  @Post('photo')
  @UseInterceptors(FileInterceptor('photo'))
  createPhote(@UploadedFile() file, @Body('id', ParseIntPipe) id: number) {
    return this.roomService.createPhote(file, id);
  }
  //删除图片
  @Delete('photo/:id')
  removePhote(@Param('id', ParseIntPipe) id: number) {
    console.log(id);
  }

  //删除房间信息
  @Delete(':id')
  remove(@Param('id', ParseIntPipe) id: number) {
    return this.roomService.remove(id);
  }
}
